<template>
  <div class="login-container">
    <el-card class="loginBox">
      <h3 class="loginTitle">手机之家后台管理系统</h3>
      <el-form :model="form" status-icon :rules="rules" ref="form" label-width="280px">
        <el-form-item label="用户名" label-width="80px" prop="username">
          <el-input type="input" v-model="form.username" auto-complete="off" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密 码" label-width="80px" prop="password">
          <el-input type="password" v-model="form.password" auto-complete="off" placeholder="请输入密码"></el-input>
        </el-form-item>
      </el-form>
      <div class="login_submit"><el-button type="primary" @click="login" class="login_submit">登&nbsp录</el-button></div>
    </el-card>
  </div>
</template>

<script>
import { getMenu } from '@/api/data.js'
export default {
  name: 'myLogin',
  data() {
    return {
      form: {},
      rules: {
        username: [
          { require: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, message: '用户名不能小于3位', trigger: 'blur' }
        ],
        password: { require: true, message: '请输入密码', trigger: 'blur' }
      }
    }
  },
  methods: {
    login() {
      getMenu(this.form).then(({ data: res }) => {
        if (res.code === 20000) {
          this.$store.commit('clearMenu')
          this.$store.commit('setMenu', res.data.menu)
          this.$store.commit('setToken', res.data.token)
          this.$store.commit('addMenu', this.$router)
          this.$router.push({ name: 'home' })
        } else {
          this.$message.warning(res.data.message)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: url('@/assets/loginBc.webp') no-repeat;
  background-size: 100%;
  .login_submit {
    margin: 0 auto;
    background-color: rgb(0, 0, 0);
    text-align: center;
    border: none;
  }
}

.loginTitle {
  margin: 20px auto;
  text-align: center;
  font-size: 1.5em;
  font-weight: bold;
  color: #08213f;
}
.el-card {
  display: block;
  width: 380px;
  border-radius: 10px;
}
</style>
